# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     report_manager.py
    Description:   报告管理
 -------------------------------------------------
 """

import os

from apitesting.common.util.logger import log
# from apitesting.utils.log_manager import log
import os

from apitesting.config import paths


# from apitesting.utils.log_manager import log


class ReportManager:
    @staticmethod
    def generate_report():
        """
        生成 Allure 报告
        """
        try:
            log.info("🛠️ 正在生成 Allure 报告...")
            os.system('allure generate ./output/report/allure-results -o ./output/report/allure-report --clean')
            log.info("✅ Allure 报告生成完成")
        except Exception as e:
            log.error(f"❌ Allure 报告生成失败: {e}")
            raise RuntimeError("报告生成失败")

    @staticmethod
    def start_allure_server(port: int = 50321):
        """
        启动 Allure 服务并显示 URL
        """
        try:
            log.info(f"🌐 正在启动 Allure 服务 (端口 {port})...")
            server_command = f"allure open --port {port} {paths.allure_report_dir.as_posix()} --no-browser"
            os.system(server_command)
            report_url = f"http://localhost:{port}/"
            log.info(f"✅ Allure 服务已启动，访问以下地址查看报告: {report_url}")
            print(f"\n👉 打开报告地址: {report_url}")
        except Exception as e:
            log.error(f"❌ 启动 Allure 服务失败: {e}")
            raise RuntimeError("启动 Allure 服务失败")


if __name__ == '__main__':
    ReportManager.start_allure_server()
    # os.system(f'allure open --port 50321 {paths.allure_report_dir.as_posix()}')
